/**
 * @param {string[]} words
 * @return {string[]}
 */
 var removeAnagrams = function(words) {
  let flag = true
  while(flag) {
    let f1 = true
    for(let i = 1; i<words.length; i++) {
      if(check(words[i-1], words[i])) {
        words.splice(i, 1)
        f1 = false
        break
      }
    }
    if(f1) flag = false
  }
  return words
  function check(w1, w2) {
    if(w1.length !== w2.length) return false
    const arr1 = w1.split('').sort()
    const arr2 = w2.split('').sort()
    for(let i = 0; i<arr1.length; i++) {
      if(arr1[i] !== arr2[i]) return false
    }
    return true
  }
};